﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GameManager : MonoBehaviour
{
    /// <summary>
    /// 总分数
    /// </summary>
    public int score;

    /// <summary>
    /// 玩家
    /// </summary>
    public GameObject player;

    #region 道具相关
    /// <summary>
    /// 恢复药预制体
    /// </summary>
    public GameObject restorationDrugPrefab;
    /// <summary>
    /// 无敌预制体
    /// </summary>
    public GameObject invinciblePrefab;
    /// <summary>
    /// 冰冻道具
    /// </summary>
    public GameObject fozenPrefab;
    /// <summary>
    /// 加速道具
    /// </summary>
    public GameObject speedupPrefab;
    /// <summary>
    /// 道具权重
    /// </summary>
    public PropsWights wights;

    #endregion

    /// <summary>
    /// GameManager单例
    /// </summary>
    public static GameManager instance; 

    private void Awake()
    {
        if (instance == null)
        {
            instance = this;
        }
    }

    /// <summary>
    /// 增加分数
    /// </summary>
    /// <param name="score">增加的分数</param>
    public void IncreaseScore(int score)
    {
        this.score += score;
    }

    /// <summary>
    /// 生成道具
    /// </summary>
    public void GenerateProps(Vector3 position,PropsType type=PropsType.None)
    {
        GameObject go=null;
        switch (type)
        {
            case PropsType.Drug:
                go = restorationDrugPrefab;
                break;
            case PropsType.Invincible:
                go = invinciblePrefab;
                break;
            case PropsType.Fozen:
                go = fozenPrefab;
                break;
            case PropsType.Speed:
                go = speedupPrefab;
                break;
            case PropsType.None:
                List<GameObject> goList = new List<GameObject>();
                int i = Random.Range(0, 101);
                PropsWights pw = new PropsWights();
                if (pw.Drug >= i) goList.Add(restorationDrugPrefab);
                if (pw.Invincible >= i) goList.Add(invinciblePrefab);
                if(pw.Fozen>=i) goList.Add(fozenPrefab);
                if(pw.Speed>=1) goList.Add(speedupPrefab);
                int j = Random.Range(0, goList.Count);
                go = goList[j];
                break;
        }

        var prop = Instantiate(go, position, Quaternion.identity);
    }


}

/// <summary>
/// 道具生成权重
/// </summary>
[System.Serializable]
public struct PropsWights
{
    [Range(0,100)]
    public int Drug;
    [Range(0, 100)]
    public int Invincible;
    [Range(0, 100)]
    public int Fozen;
    [Range(0, 100)]
    public int Speed;
}


/// <summary>
/// 道具类型
/// </summary>
public enum PropsType
{
    /// <summary>
    /// 药
    /// </summary>
    Drug,
    /// <summary>
    /// 无敌
    /// </summary>
    Invincible,
    /// <summary>
    /// 冰冻
    /// </summary>
    Fozen,
    /// <summary>
    /// 加速
    /// </summary>
    Speed,
    None
}
